'use strict';
import React from "react";
import {View, StyleSheet, Text, TouchableOpacity, ScrollView} from "react-native";
import Container from "../../component/common/Container";
import {diffTime} from "../../util/Tool";
import HTMLView from "../../component/common/HTMLView";
import NavigationBar from "../../component/navigation/NavigationBar";
import {inject, observer} from "mobx-react";
@inject('taskStore')
@observer
class NewestArticleDetail extends React.Component {

    constructor(props) {
        super(props);
        const {params} = this.props.navigation.state;
        this.item = params.item;
    }

    componentDidMount(){
        this._readTimes();
    }

    //记录阅读次数
    _readTimes = async () => {
        const {taskStore} = this.props;
        const saveRes = await taskStore.saveTask('reading');
        // console.log('新闻详情保存任务------------>',saveRes);
    };

    render() {
        const {title,published_at,content} = this.item;
        return (
            <Container style={styles.container}>
                <NavigationBar
                    title={title}
                />
                {/*<Text style={styles.title}>{title}</Text>*/}
                <ScrollView>
                    <HTMLView
                        imageStyle={null}
                        containerStyle={styles.htmlContainer}
                        html={`<div style="paddingLeft: 15px;paddingRight: 15px;paddingTop: 22px;color: #9d9d9d;font-size: 12px;line-height: 20px;">${content}</div>`}
                        maxImageWidth={Theme.screenWidth - 20}
                    />
                    <Text style={styles.number}>发布时间：{published_at ? published_at : 0}</Text>
                </ScrollView>
            </Container>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        // paddingTop: 94,
        backgroundColor: '#fff',
    },
    title: {
        fontSize: FontSize(16),
        color: '#212121',
        marginTop: 11,
        marginLeft: 15,
        marginRight: 15,
    },
    number: {
        fontSize: FontSize(11),
        color: '#9d9d9d',
        marginRight: 15,
        alignSelf: 'flex-end',
        marginTop: 15,
    },
    htmlContainer: {
        flex: 1,
    },
});

export default NewestArticleDetail